function beta=sgd(data,lambda0,mu)
	X = data(:,1:size(data,2)-1);
	y = data(:,size(data,2));
	[n,d] = size(X);
	beta = zeros(1,d);
	error = 1;
	epoch = 1;
	threshold = .001;
	c = 5;
    errors = [];
	while error > threshold & epoch < 40
% 	while error > threshold 
        %lambda = lambda0;
		lambda = lambda0/c^epoch;        
% 		lambda = lambda0/(1+lambda0*c*epoch);
        
        error = 0;
		for i=1:n
			x_i = X(i,:);
			y_i = y(i);
			p_i = p(x_i,beta);
			yp = y_i - p_i;
            nbeta = beta + lambda*(yp*x_i - 2*mu*beta);
            error = error+sum(abs(nbeta - beta));
            beta = nbeta;
        end
        
        error=error/n
        errors(epoch) = error;
        epoch = epoch + 1
    end
    
%     plot(errors);
end
